#include "controls.h"


void InitControls(void)
{
	DPAD_UP_TRIS=1;	//up is input
	DPAD_DOWN_TRIS=1;	//down is input
	DPAD_LEFT_TRIS=1;	//left is input
	DPAD_RIGHT_TRIS=1;	//right is input
}

unsigned char ReadButtons(void)
{
	unsigned char lastcontrolsc;
	if(DPAD_UP==0){lastcontrolsc|=_BV(1);}	//bit1 = UP button pressed
	else {lastcontrolsc&= ~(_BV(1));}
	if(DPAD_DOWN==0){lastcontrolsc|=_BV(2);}	//bit2 = DOWN button pressed
	else {lastcontrolsc&= ~(_BV(2));}
	if(DPAD_LEFT==0){lastcontrolsc|=_BV(3);}	//bit3 = LEFT button pressed
	else {lastcontrolsc&= ~(_BV(3));}
	if(DPAD_RIGHT==0){lastcontrolsc|=_BV(4);}//bit4 = RIGHT button pressed
	else {lastcontrolsc&= ~(_BV(4));}
	return lastcontrolsc;
}

void ButtonChanged(void)
{
	if (ReadButtons()==lastcontrols)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

unsigned char GetButtons(void)
{
	lastcontrols=ReadButtons();
	return lastcontrols;
}


